//
//  UIView+xib.swift
//  SkylowAPP
//
//  Created by 青色石头 on 2024/9/22.
//

import Foundation

extension UIView {

    class func loadFromXib() -> Self? {
        let bundle = Bundle(for: self)
        guard let name = NSStringFromClass(self).components(separatedBy: ".").last else {
            return nil
        }
        return bundle.loadNibNamed(name, owner: nil, options: nil)?.first as? Self
    }

    
    /**
     * 切圆角
     * - Parameters:
     *  - conrners
     *  - radius 圆角弧度
     */
    func addCorner(conrners: UIRectCorner , radius: CGFloat) {
        let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: conrners, cornerRadii: CGSize(width: radius, height: radius))
        let maskLayer = CAShapeLayer.init()
        maskLayer.frame = self.bounds
        maskLayer.path = maskPath.cgPath
        self.layer.mask = maskLayer
    }
    
}
